<?php
/**
 * TeacherController.class.php
 * 教师控制器
 * 
 * @author 	王中艺	<wangzy_smile@qq.com>
 * @date 	2017-03-03
 */
namespace Admin\Controller;

class TeacherController extends BaseController {
	/**
	 * 获取教师列表
	 * @param   $p 页码数
	 * @return  json [<description>]
	 */
	function getList(){
		$page 	= $this->iInfo['p'] ? $this->iInfo['p'] : 1;
		$pageHtml 	= '';
		$list 	= D('Teacher')->getList($page, $pageHtml);
		$this->outOInfo(array('list' => $list, 'page_html' => $pageHtml));
	}

	/**
	 * 添加信息
	 * @param   $name 教师名称
	 * @param   $decipt 描述
	 * @param   $sex 性别
	 * @param   $phone 手机号
	 * @return  boolean [<description>]
	 */
	function add(){
		$this->unEmptyParam(array('name', 'decipt', 'sex', 'phone'));
		$name 	= $this->iInfo['name'];
		$decipt 	= $this->iInfo['decipt'];
		$sex 	= $this->iInfo['sex'];
		$phone 	= $this->iInfo['phone'];

		$result 	= D('Teacher')->addItem($name, $decipt, $sex, $phone);
		if($result === false)
			$this->outOInfo(D('Teacher')->errMsg, 0);
		$this->outOInfo('Oh yes!');
	}

	/**
	 * 编辑信息
	 * @param   $teacher_id 教师ID
	 * @param   $teacher_info 教师信息
	 * @return  json [<description>]
	 */
	function change(){
		$this->unEmptyParam(array('teacher_id', 'teacher_info'));
		$teacherId 	= $this->iInfo['teacher_id'];
		$teacherInfo 	= $this->iInfo['teacher_info'];

		$result 	= D('Teacher')->change($teacherId, $teacherInfo);
		if($result === false)
			$this->outOInfo(D('Teacher')->errMsg, 0);
		$this->outOInfo('Oh yes!');
	}

	/**
	 * 删除信息
	 * @param   $teacher_id 教师ID
	 * @return  boolean [<description>]
	 */
	function delete(){
		$this->unEmptyParam(array('teacher_id'));
		$teacherId 	= $this->iInfo['teacher_id'];

		$result 	= D('Teacher')->deleteItem($teacherId);
		if($result === false)
			$this->outOInfo(D('Teacher')->errMsg, 0);
		$this->outOInfo('Oh yes!');
	}
}
